package com.ts.api.module.api.convert.receive.adapter;

import com.alibaba.fastjson.JSONObject;
import com.gitee.apanlh.util.base.Eq;
import com.gitee.apanlh.util.base.MapUtils;
import com.gitee.apanlh.util.dataformat.JsonUtils;
import com.ts.api.common.constant.api.ApiApplyQueryStatusEnum;
import com.ts.api.module.api.convert.receive.entity.ApiReceiveNotice;
import com.ts.api.module.api.convert.receive.handler.ApiReceiveNoticeHandler;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 *  上游-对方接入我方-默认进件成功回调
 *
 *  @author Pan
 */
@Service("apiReceivePushApplyNoticeAdapter")
public class ApiReceivePushApplyNoticeAdapter implements ApiReceiveNoticeHandler {

    @Override
    public Map<String, Object> buildRequest(ApiReceiveNotice apiReceiveNotice) throws Exception {
        String applyId = apiReceiveNotice.getPhoneMd5();
        return MapUtils.newHashMap(newMap -> {
            newMap.put("applyId", applyId);
            newMap.put("phoneMd5", applyId);
            newMap.put("status", ApiApplyQueryStatusEnum.SUC.getType().toString());
        });
    }

    @Override
    public boolean hasSuc(String respJson) throws Exception {
        JSONObject jsonObject = JsonUtils.get(respJson);
        if (jsonObject == null) {
            return false;
        }
        return Eq.object(jsonObject.getInteger("code"), 1000);
    }
}
